package com.wyg.observer;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @description:    被观察者抽象类
 * @author: WYG
 * @time: 2021/4/27 9:55
 */

public abstract class NumberGenerator {
    private ArrayList<Observer> observers = new ArrayList<>();
    public void addObserver(Observer observer) {
        observers.add(observer);
    }
    public void deleteObserver(Observer observer) {
        observers.remove(observer);
    }
    public void notifyObservers() {
        Iterator<Observer> iterator = observers.iterator();
        while (iterator.hasNext()) {
            Observer observer = (Observer) iterator.next();
            observer.update(this);
        }
    }

    /**
     * 获取随机数值
     * @return
     */
    public abstract int getNumber();

    /**
     * 生成随机数值
     */
    public abstract void execute();
}
